'''
Created on Aug 25, 2011

@author: david
'''

from pspy.gae.actiondomain import PspyAction

class Reset(PspyAction):
    """
    Default Action 
    spawns index.gen
    """
    def execute(self): 
        from app.Ranger.agents import AccessAgent
        
        req = self.request
        rslts = "100::Ok"
        
        # get input
        pwd = req.getParameter("pwd",'none')
        
        # check for pwd entry
        if pwd == 'none':
            # extract acct id
            aid = req.getParameter("c").split("-")[1].split("_")[0]
            
            #send out page for new pwdd                
            req.setAttribute("aid",aid)
            req.setAttribute("results",rslts)    
            req.setResponsePage("/Ranger/acct/Reset.gen")        
        
        else:
            # reset pwd and go to index
            aid = req.getParameter("aid")
            AccessAgent().reset(aid,pwd)
            
            # all done here
            req.setAttribute("results",rslts)    
            req.setResponsePage("/Ranger/Index.gen")        
        
        return req.getResponse()

    def sess_check(self):
        return True